/*
 * @Description: 
 * @Author: Dxcr
 * @Date: 2024-08-20 09:10:45
 * @LastEditTime: 2024-08-20 10:26:04
 * @LastEditors: Dxcr
 */
mod excel_reader;
use excel_reader::ExcelReader;
use rfd::FileDialog;
fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 让用户选择 Excel 文件
    let file_path = {
        let dialog = FileDialog::new()
            .add_filter("Excel files", &["xlsx","xls"]);
        dialog.pick_file()
            .ok_or("No file selected")?
            .to_str()
            .ok_or("Failed to convert file path to string")?
            .to_string()
    };
    
     // 创建 ExcelReader 实例
     let mut reader = ExcelReader::new(&file_path)?;

     // 让用户选择输出 JSON 文件的位置
     let output_file = {
        let dialog = FileDialog::new()
            .add_filter("JSON files", &["json"]);
        dialog.save_file()
            .ok_or("No output file selected")?
            .to_str()
            .ok_or("Failed to convert output file path to string")?
            .to_string()
    };

 
     // 保存 JSON 数据到选定的文件
     reader.save_json_to_file("Sheet1", &output_file)?;
     println!("JSON data has been saved to {}", output_file);
 
     Ok(())
}